<?php
/**
 * 重新加载历史记录数据
 *
 *
 *
 * @copyright  Copyright (c) 2014-2015 TuntronKJ Inc. (http://www.tuntron.com)
 * @license    http://www.tuntron.com
 * @link       http://www.tuntron.com
 * @since      File available since Release v1.1
 */
defined('InTuntronKJ') or exit('Access Invalid!');
class RefreshHistoryDataControl extends BaseLotteryHallControl{
	public function indexOp(){
		//中奖记录(20条)和最近投注记录 查询时间为当日3点至第二日凌晨3点

		$model_bets = Model('bat');
		$model_member = Model('member');
		$model_data = Model('data_class');
		$model_kjtype = Model('kjtype');
		$model_play = Model("played");
		
		$today_zero = strtotime('today');
		$time = time();
		$fromTime = $today_zero+3600*3;			//查询起始时间
		if($fromTime > $time){
			$toTime = $fromTime;				//查询结束时间
			$fromTime = $today_zero-3600*21;			
		}else{
			$toTime = $fromTime+3600*24;
		}

		$page = $_POST['page']?$_POST['page']:1;
		$start = 10*$page-10;
		
		$param['type'] = 1;
		$param['actionTime'] = array('between',$fromTime.','.$toTime);
		$param['bonus'] = array('between','1');
		$data_zj = array();
		 
		//中奖记录-最新一期开奖中奖纪录
		//获取上次开奖期数以及时间
		$thisLastNoType = $model_kjtype->getGameLastNo($param['type']);
		$actionNo = date('Ymd', time()).'-'.sprintf("%03d",$thisLastNoType['actionNo']);		
		$param['actionNo'] = $actionNo;
		
		$win_list = $model_bets->getBetList($param,'','',20);
		if(!empty($win_list) && is_array($win_list)){
			foreach($win_list as $key=>$item){
				$playinfo = $model_play->getPlayInfo(array('id'=>$item['playedId']));

				$data_zj['top10'][$key][] = $item['actionData'];							//投注号码
				$data_zj['top10'][$key][] = $item['wjorderId'];								//订单ID
				$data_zj['top10'][$key][] = '匿名';											//发单人
				$data_zj['top10'][$key][] = number_format($item['mode'],2);					//单注金额
				$data_zj['top10'][$key][] = '重庆彩';										//彩种
				$data_zj['top10'][$key][] = $item['actionNo'];								//期号
				$data_zj['top10'][$key][] = $playinfo['name'];								//玩法
				$data_zj['top10'][$key][] = $item['lotteryNo'];								//开奖号码
				$data_zj['top10'][$key][] = $item['actionNum']*$item['beiShu'];								//投注数量
				$data_zj['top10'][$key][] = number_format($item['mode']*$item['actionNum']*$item['beiShu'],2);	//投注总额
				$data_zj['top10'][$key][] = $item['zjCount'];								//中奖注数
				$data_zj['top10'][$key][] = number_format($item['bonus'],2);				//中奖金额
				$data_zj['top10'][$key][] = $item['bonusProp'];								//奖金/赔率
				$data_zj['top10'][$key][] = $item['fanDian'].''.$item['fanDianAmount'];		//返点与返点金额(有返点则：返点金额=投注总额X返点)
				$data_zj['top10'][$key][] = date('Y-m-d', $item['actionTime']);				//交易时间
				$data_zj['top10'][$key][] = '赢(中奖)';										//状态
				$data_zj['top10'][$key][] = number_format(($item['bonus']-$item['beiShu']*$item['actionNum']*$item['mode']),2);	//盈亏
			}			
		}
		
		//最近投注记录		
		$param2['type'] = 1;
		$param2['isDelete'] = 0;
		$param2['uid'] = $_SESSION['uid'];
		$param2['actionTime'] = array('between',$fromTime.','.$toTime);
		$member_info = $model_member->getMemberInfo(array('uid'=>$_SESSION['uid']));
		$bets_list = $model_bets->getBetList($param2,'','',$start.',10','actionTime desc');
		$bets_count = $model_bets->getCount($param2);		
		
		if(!empty($bets_list) && is_array($bets_list)){
			if($bets_count%10 == 0){
				$totalpage = $bets_count/10;
			}else{
				$totalpage = intval($bets_count/10)+1;
			}
			
			$data_zj['recentData']['totalPages'] = $totalpage;
			$data_zj['recentData']['totalRecords'] = $bets_count;			
			foreach($bets_list as $key=>$value){
				$playinfo = $model_play->getPlayInfo(array('id'=>$value['playedId']));

				$data_zj['recentData']['rows'][$key]['RowNumber'] = $key+1;
				$data_zj['recentData']['rows'][$key]['BetContent'] = $value['actionData'];						//投注号码
				$data_zj['recentData']['rows'][$key]['BonusNumber'] = $value['lotteryNo'];						//开奖号码
				$data_zj['recentData']['rows'][$key]['InsertDate'] = date('Y-m-d H:i:s', $value['actionTime']);	//投注时间
				$data_zj['recentData']['rows'][$key]['UserName'] = $value['username'];							//用户名
				$data_zj['recentData']['rows'][$key]['UserType'] = $member_info['type']==0?'会员':'代理';		//用户类型
				$data_zj['recentData']['rows'][$key]['RuleName'] = $playinfo['name'];							//玩法
				$data_zj['recentData']['rows'][$key]['LotteryName'] = '重庆时时彩';								//彩种
				$data_zj['recentData']['rows'][$key]['Id'] = $value['id'];
				$data_zj['recentData']['rows'][$key]['Uid'] = $value['uid'];									//用户UID
				$data_zj['recentData']['rows'][$key]['MemberId'] = $_SESSION['uid'];
				$data_zj['recentData']['rows'][$key]['LotteryId'] = 1;											//彩种ID
				$data_zj['recentData']['rows'][$key]['IssueNumber'] = $value['actionNo'];						//期号
				$data_zj['recentData']['rows'][$key]['BetRuleId'] = $value['playedId'];							//玩法ID
				$data_zj['recentData']['rows'][$key]['BetUnitPrice'] = $value['mode'];							//单注金额
				$data_zj['recentData']['rows'][$key]['UnitPaymentPrice'] = $value['bonusProp'];					//赔率
				$data_zj['recentData']['rows'][$key]['ReturnPoint'] = $value['fanDian'];						//返点
				$data_zj['recentData']['rows'][$key]['OrderDate'] = "/Date(".$value['actionTime'].")/";
				$data_zj['recentData']['rows'][$key]['OrderStatus'] = $value['isDelete']?10:0;					//订单状态 10：撤单
				$data_zj['recentData']['rows'][$key]['TotalBet'] = $value['actionNum']*$value['beiShu'];		//投注数
				$data_zj['recentData']['rows'][$key]['OrderGuid'] = $value['serializeId'];		
				$data_zj['recentData']['rows'][$key]['BonusTotalNumber'] = $value['zjCount'];					//中奖注数
				$data_zj['recentData']['rows'][$key]['Description'] = '重庆时时彩 '.$value['actionNo'].'期 '.$playinfo['name'];		//说明
				$data_zj['recentData']['rows'][$key]['profit'] = number_format(($value['bonus']-$value['beiShu']*$value['actionNum']*$value['mode']),2);	//盈亏
				//是否开奖				
				$kjdata = $model_data->getDataList(array('number'=>$value['actionNo'],'type'=>1));
				if($kjdata){
					$data_zj['recentData']['rows'][$key]['hasRunLottery'] = "是";
				}else{
					$data_zj['recentData']['rows'][$key]['hasRunLottery'] = "否";
				}				
				$data_zj['recentData']['rows'][$key]['BonusMoney'] = $value['bonus'];							//中奖金额
				$data_zj['recentData']['rows'][$key]['EncodeId'] = $value['wjorderId'];							//订单号
				$data_zj['recentData']['lotteryNumberDict']['1,'.$value['actionNo']] = $value['lotteryNo'];
			}			
		}

		$output = json_encode($data_zj);
		echo $output;
		exit();
		
// 		echo '{"top10":[[",0123456,012345678,,","A6DA1C33","匿名","1,220.00","重庆彩","20150122-034","五星定位胆","8,3,0,7,8","16","19,520.00","2","23,668.00","19.40 / 9.70","0.00% 0.00","2015-01-22","赢(中奖)","4,148.00","44143574"],["83","0E9E13B4","匿名","230.00","重庆彩","20150122-034","前二直选单式","8,3,0,7,8","1","230.00","1","22,310.00","194.00 / 97.00","0.00% 0.00","2015-01-22","赢(中奖)","22,080.00","9448320"],[",,,012345678,678","C2D6248F","匿名","1,060.00","重庆彩","20150122-034","五星定位胆","8,3,0,7,8","12","12,720.00","2","20,458.00","19.30 / 9.65","0.00% 0.00","2015-01-22","赢(中奖)","7,738.00","90260546"],[",,,,78","9EDE0760","匿名","2,000.00","重庆彩","20150122-034","五星定位胆","8,3,0,7,8","2","4,000.00","1","19,200.00","19.20 / 9.60","0.00% 0.00","2015-01-22","赢(中奖)","15,200.00","57441958"],["8,0123456","2F04271D","匿名","185.00","重庆彩","20150122-034","前二直选复式","8,3,0,7,8","7","1,295.00","1","17,760.00","192.00 / 96.00","0.00% 0.00","2015-01-22","赢(中奖)","16,465.00","11220716"],["18","69B5DDFF","匿名","4,840.00","重庆彩","20150122-034","后三不定位","8,3,0,7,8","2","9,680.00","1","16,456.00","6.80 / 3.40","3.50% 338.80","2015-01-22","赢(中奖)","7,114.80","2139400"],[",,012345678,567,","0C67CC46","匿名","830.00","重庆彩","20150122-034","五星定位胆","8,3,0,7,8","12","9,960.00","2","15,936.00","19.20 / 9.60","0.00% 0.00","2015-01-22","赢(中奖)","5,976.00","41588241"],["8","DFCF96C3","匿名","4,320.00","重庆彩","20150122-034","前三不定位","8,3,0,7,8","1","4,320.00","1","14,688.00","6.80 / 3.40","3.50% 151.20","2015-01-22","赢(中奖)","10,519.20","45593616"],["78","01BD6B59","匿名","145.00","重庆彩","20150122-034","后二直选单式","8,3,0,7,8","1","145.00","1","14,065.00","194.00 / 97.00","0.00% 0.00","2015-01-22","赢(中奖)","13,920.00","58721538"],["01","9927656C","匿名","3,660.00","重庆彩","20150122-034","前三不定位","8,3,0,7,8","2","7,320.00","1","12,444.00","6.80 / 3.40","3.50% 256.20","2015-01-22","赢(中奖)","5,380.20","17264479"],[",01234,0123456,,","7641C296","匿名","630.00","重庆彩","20150122-034","五星定位胆","8,3,0,7,8","12","7,560.00","2","12,159.00","19.30 / 9.65","0.00% 0.00","2015-01-22","赢(中奖)","4,599.00","3979524"],["78","8754D109","匿名","120.00","重庆彩","20150122-034","后二直选单式","8,3,0,7,8","1","120.00","1","11,520.00","192.00 / 96.00","0.00% 0.00","2015-01-22","赢(中奖)","11,400.00","88945717"],[",,,1234567,012345678","8068C5C7","匿名","530.00","重庆彩","20150122-034","五星定位胆","8,3,0,7,8","16","8,480.00","2","10,229.00","19.30 / 9.65","0.00% 0.00","2015-01-22","赢(中奖)","1,749.00","65057446"],["8","3A137778","匿名","2,760.00","重庆彩","20150122-034","前三不定位","8,3,0,7,8","1","2,760.00","1","9,384.00","6.80 / 3.40","3.50% 96.60","2015-01-22","赢(中奖)","6,720.60","39798772"],["45678,0123456,,,","D5912B9C","匿名","460.00","重庆彩","20150122-034","五星定位胆","8,3,0,7,8","12","5,520.00","2","8,878.00","19.30 / 9.65","0.00% 0.00","2015-01-22","赢(中奖)","3,358.00","48814007"],["2345678,3","45FA9D37","匿名","85.00","重庆彩","20150122-034","前二直选复式","8,3,0,7,8","7","595.00","1","8,202.50","193.00 / 96.50","0.00% 0.00","2015-01-22","赢(中奖)","7,607.50","59475280"],[",,01234,1234567,","F9965CB7","匿名","395.00","重庆彩","20150122-034","五星定位胆","8,3,0,7,8","12","4,740.00","2","7,623.50","19.30 / 9.65","0.00% 0.00","2015-01-22","赢(中奖)","2,883.50","30102767"],["18,28,38,48,58,68,78","948D92AC","匿名","70.00","重庆彩","20150122-034","后二直选单式","8,3,0,7,8","7","490.00","1","6,720.00","192.00 / 96.00","0.00% 0.00","2015-01-22","赢(中奖)","6,230.00","91367117"],["2345678,,,,45678","CE682D0B","匿名","310.00","重庆彩","20150122-034","五星定位胆","8,3,0,7,8","12","3,720.00","2","5,952.00","19.20 / 9.60","0.00% 0.00","2015-01-22","赢(中奖)","2,232.00","84169445"],["134","91B7E4DC","匿名","1,660.00","重庆彩","20150122-034","前三不定位","8,3,0,7,8","3","4,980.00","1","5,644.00","6.80 / 3.40","3.50% 174.30","2015-01-22","赢(中奖)","838.30","3231935"]],"recentData":{"totalPages":1,"totalRecords":5,"rows":[{"RowNumber":1,"BetContent":"6,5,9","BonusNumber":"6,3,7,6,4","InsertDate":"2015-01-19 12:07:19","UserName":"haossc","UserType":"会员","RuleName":"后三直选复式","LotteryName":"重庆彩","Id":16037965,"Uid":167009,"LotteryId":1,"IssueNumber":"20150119-037","BetRuleId":11,"BetUnitPrice":2.0000,"UnitPaymentPrice":865.0000,"ReturnPoint":0.095,"OrderDate":"\/Date(1421640439250)\/","OrderStatus":1,"TotalBet":1,"OrderGuid":"0x57af46867fbf3219c4775329b9b2a683","BonusTotalNumber":0,"Description":"重庆彩 20150119-037期 后三直选复式","profit":-1.810000,"hasRunLottery":"是","BonusMoney":0.0000,"EncodeId":"062CCB50"},{"RowNumber":2,"BetContent":"2,0,4","BonusNumber":"0,5,7,6,4","InsertDate":"2015-01-19 10:38:54","UserName":"haossc","UserType":"会员","RuleName":"后三直选复式","LotteryName":"重庆彩","Id":16031197,"Uid":167009,"LotteryId":1,"IssueNumber":"20150119-028","BetRuleId":11,"BetUnitPrice":2.0000,"UnitPaymentPrice":865.0000,"ReturnPoint":0.095,"OrderDate":"\/Date(1421635134377)\/","OrderStatus":1,"TotalBet":1,"OrderGuid":"0x4f22a19241cb09e97e0a814545256ac1","BonusTotalNumber":0,"Description":"重庆彩 20150119-028期 后三直选复式","profit":-1.810000,"hasRunLottery":"是","BonusMoney":0.0000,"EncodeId":"EBD5B1A2"},{"RowNumber":3,"BetContent":"6,1,8","BonusNumber":"9,3,3,0,9","InsertDate":"2015-01-14 00:03:39","UserName":"haossc","UserType":"会员","RuleName":"后三直选复式","LotteryName":"重庆彩","Id":15619244,"Uid":167009,"LotteryId":1,"IssueNumber":"20150114-001","BetRuleId":11,"BetUnitPrice":2.0000,"UnitPaymentPrice":865.0000,"ReturnPoint":0.095,"OrderDate":"\/Date(1421165019453)\/","OrderStatus":1,"TotalBet":1,"OrderGuid":"0xb45e58b5d565d1a4c5892799610f2f19","BonusTotalNumber":0,"Description":"重庆彩 20150114-001期 后三直选复式","profit":-1.810000,"hasRunLottery":"是","BonusMoney":0.0000,"EncodeId":"52758285"},{"RowNumber":4,"BetContent":"3,4,7","BonusNumber":"0,3,1,7,0","InsertDate":"2015-01-13 23:32:04","UserName":"haossc","UserType":"会员","RuleName":"后三直选复式","LotteryName":"重庆彩","Id":15615969,"Uid":167009,"LotteryId":1,"IssueNumber":"20150113-115","BetRuleId":11,"BetUnitPrice":2.0000,"UnitPaymentPrice":865.0000,"ReturnPoint":0.095,"OrderDate":"\/Date(1421163124540)\/","OrderStatus":1,"TotalBet":1,"OrderGuid":"0xa114841d52f2e1c44419b8806751e7b0","BonusTotalNumber":0,"Description":"重庆彩 20150113-115期 后三直选复式","profit":-1.810000,"hasRunLottery":"是","BonusMoney":0.0000,"EncodeId":"771D5033"},{"RowNumber":5,"BetContent":"2,3,7","BonusNumber":"8,3,2,1,5","InsertDate":"2015-01-07 11:40:56","UserName":"haossc","UserType":"会员","RuleName":"后三直选复式","LotteryName":"重庆彩","Id":15088550,"Uid":167009,"LotteryId":1,"IssueNumber":"20150107-035","BetRuleId":11,"BetUnitPrice":2.0000,"UnitPaymentPrice":815.0000,"ReturnPoint":0.145,"OrderDate":"\/Date(1420602056017)\/","OrderStatus":1,"TotalBet":1,"OrderGuid":"0x5c8941c61f839feaaf4507bac92cc691","BonusTotalNumber":0,"Description":"重庆彩 20150107-035期 后三直选复式","profit":-1.710000,"hasRunLottery":"是","BonusMoney":0.0000,"EncodeId":"49C939B3"}],"lotteryNumberDict":{"1,20150119-037":"6,3,7,6,4","1,20150119-028":"0,5,7,6,4","1,20150114-001":"9,3,3,0,9","1,20150113-115":"0,3,1,7,0","1,20150107-035":"8,3,2,1,5"}}}';
	}



}
